/*******************************************************************************
Title: Individualism during Crisis 
Authors: Bo Bian, Jingjing Li, Ting Xu, Natasha Z. Foutz
Purpose: Produce the following tables and figures
         - Table 8 Panel A
		 - Appendix Table A17 Panel A, Panel C
		 - Appendix Table A18
		 - Appendix Figure A8, A9
*******************************************************************************/

clear all
set more off
set matsize 5000
cap log close
set linesize 200

log using "tables\rep_country_level", replace
use "data\rep_country_level_sample.dta", clear

* country-level regressions (OLS and IV)
g idv_post=idv*post_lockdown
g distM_UK_post=distM_UK*post_lockdown
egen iso2_fe=group(iso2)

eststo first: quietly reghdfe idv_post distM_UK_post post_lockdown, ab(iso2 date) cl(iso2) 

foreach y of varlist pctchg_retailrecreation pctchg_grocery_phamacy pctchg_parks pctchg_transit_stations pctchg_workplaces pctchg_residential {
	eststo ols_`y': quietly reghdfe `y' c.idv##c.post_lockdown if distM_UK_post<., ab(iso2 date) cluster(iso2)
}

foreach y of varlist pctchg_retailrecreation pctchg_grocery_phamacy pctchg_parks pctchg_transit_stations pctchg_workplaces pctchg_residential {
	eststo iv_`y': quietly capture ivreg2 `y' (c.idv#c.post_lockdown=c.distM_UK#c.post_lockdown) post_lockdown i.iso2_fe i.date, cluster(iso2) 
	qui estadd scalar F_stat=e(widstat)
}

******************************************************************************** 
* Table 8 Panel A 
********************************************************************************
esttab first ols_pctchg_residential iv_pctchg_residential, scalars(F_stat) ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table 8 Panel A) keep(c.idv#c.post_lockdown distM_UK_post *post*) order(c.idv#c.post_lockdown distM_UK_post *post*) replace

******************************************************************************** 
* Table A17 Panel A (summary stat)
********************************************************************************
tabstat pctchg_grocery_phamacy pctchg_workplaces pctchg_retailrecreation pctchg_transit_stations pctchg_parks pctchg_residential if post_lockdown==1, stat(N mean sd min p50 max) columns(s) varwidth(20) format(%9.3gc)

******************************************************************************** 
* Table A17 Panel C (summary stat)
********************************************************************************
tabstat idv if date==mdy(03,01,2020), stat(N mean sd min p50 max) columns(s) varwidth(20) format(%9.3gc)

******************************************************************************** 
* Table A18 Panel A
********************************************************************************
esttab ols_*_grocery* ols_*_work* ols_*_retail* ols_*_transit* ols_*_parks, ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A18 Panel A) keep(c.idv#c.post_lockdown *post*) order(c.idv#c.post_lockdown *post*) replace

******************************************************************************** 
* Table A18 Panel B
********************************************************************************
esttab iv_*_grocery* iv_*_work* iv_*_retail* iv_*_transit* iv_*_parks , scalars(F_stat) ar2 star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) br mtitle title(Table A18 Panel B) keep(c.idv#c.post_lockdown *post*) order(c.idv#c.post_lockdown *post*) replace


******************************************************************************** 
* Figure A8
********************************************************************************
use "data\rep_country_level_cross-sectional_sample.dta", clear
foreach y in pctchg_grocery_phamacy pctchg_workplaces pctchg_retailrecreation pctchg_transit_stations pctchg_parks pctchg_residential {
graph tw (lfitci `y' idv) ///
	|| (scatter `y' idv, mlabel(iso2) mlabsize(vsmall)) ///
	, ytitle("Percent change from pre-covid19 value") ///
	xtitle("Individualism") scheme(s2mono) ///
	legend(off) 
	graph export "figures\AF8_`y'.pdf", replace	
	graph export "figures_png\AF8_`y'.png", replace
}

******************************************************************************** 
* Figure A9
********************************************************************************
foreach y in g_30dfrom100confirmed g_30dfrom10deaths {
graph tw (lfitci `y' idv) ///
	|| (scatter `y' idv, mlabel(iso2) mlabsize(vsmall)) ///
	, ytitle("Percent change from pre-covid19 value") ///
	xtitle("Individualism") scheme(s2mono) ///
	legend(off) 
	graph export "figures\AF9_`y'.pdf", replace	
	graph export "figures_png\AF9_`y'.png", replace
}

log close